package com.electronicmallapiidea;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electronicmallapiidea.entity.LoginForm;
import com.electronicmallapiidea.entity.User;
import com.electronicmallapiidea.entity.dto.UserDTO;
import com.electronicmallapiidea.mapper.UserMapper;
import com.electronicmallapiidea.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@SpringBootTest
public class Demo04_IService extends ServiceImpl<UserMapper, User> implements UserService {
    User user = new User(null, "wrk", "21", "2332", "fjdslf", "fjdslf", "dfjsd", "fjdsf", "fjskdf");


//    新增数据
    @Test
    void save() {
        List<User> list = new ArrayList<>();
        list.add(user);
        list.add(user);
        list.add(user);
        save(user);     //保存一条数据
        saveBatch(list);        //批量添加
        saveBatch(list, 3);      //参数2是数据条数，数字不能小于list数量

    }

//    删除数据
    @Test
    void delete(){
        /*
        删除一条数据
         */
//        removeById(1);

        /*
        根据map条件，删除数据
         */
//        HashMap<String, Object> param = new HashMap<>();
//        param.put("id",3);
//        param.put("username","wrk1");
//        removeByMap(param);

        /*
        根据wrapper封装条件删除
         */
//        QueryWrapper<User> wrapper = Wrappers.query();
//        wrapper.eq("id",5);
//        remove(wrapper);

        /*
        批量删除
         */
//        ArrayList<String> users = new ArrayList<>();
//        users.add("24");
//        users.add("25");
//        users.add("26");
//        removeByIds(users);


    }

//    修改数据
    @Test
    void upd(){

    }




























    @Override
    public UserDTO login(LoginForm loginForm) {
        return null;
    }

    @Override
    public User register(LoginForm loginForm) {
        return null;
    }

    @Override
    public User getOne(String username) {
        return null;
    }
}
